package aimis.domain;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = {"name","parent"})
@ToString(exclude = {"root","parent"})
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "parent_id" }) })
@JsonIgnoreProperties(ignoreUnknown = true)
public class Department {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 部门名称
     */
    @Column(nullable = false)
    private String name;
    /**
     * 当前层级下的排序
     */
    @Column(nullable = false)
    private Integer sort = 0;
    /**
     * 是否可以访问所有部门的数据
     */
    private Boolean accessAllDepartment=false;
    /**
     * 父级主键id
     */
    @ManyToOne
    private Department parent;
    /**
     * 根部门
     */
    @ManyToOne
    @JsonIgnore
    private Department root;
    /**
     * 部门地址
     */
    private String address;
    /**
     * 部门负责人
     */
    private String responsiblePerson;
    /**
     * 部门描述
     */
    @Column
    private String description;
    @OneToMany(mappedBy = "parent")
    @JsonIgnoreProperties(value="parent",allowSetters = true)
    private Set<Department> children=new HashSet<>();
}

